// pages/dangerDetailPage/dangerDetailPage.js
var app = getApp()
var util = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
      title:'',
      dangerList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
        title:options.title
    });
    this.getDangerList()
  },
    //获取隐患列表
    getDangerList:function () {
        let that = this;
        let startDate = new Date();
        let currentYear=startDate.getFullYear();
        startDate.setFullYear(currentYear,0,1);
        let endDate = new Date();
        endDate.setFullYear(currentYear,11,31);
        
        let params={needChange:1,downward:true,startDate:startDate,endDate:endDate,hiddenDangerLevel:this.data.title};
        this.setData({
            dangerList:[]
        })
        wx.showLoading()
        wx.request({
            url: app.globalData.baseUrl + '/safe/danger/inspectListPublic/find',
            header: {'Cookie': wx.getStorageSync("sessionid")},
            method: "POST",
            data: params,
            success(res) {
              if(res.data.success){
                let list=res.data.data;
                list.forEach(function (item) {
                  if(item.changeTime){
                    let dateTemp=new Date()
                    dateTemp.setTime(item.changeTime)
                    item.timeStr=util.formatTime(dateTemp)
                  }else {
                      item.timeStr='未整改'
                  }
                });
                that.setData({
                    dangerList:list
                })
              }
                //关闭加载
                wx.hideLoading()
            },
            fail(){
                //关闭加载
                wx.hideLoading()
            }
        })
    },
    //返回
    onClickLeft:function () {
        wx.navigateBack({
            delta: 1
        })
    }
})